home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / misc / gnuplot < prev    next >
Text File  |  1995-10-08  |  48KB  |  1,985 lines

  1. //-------------------------------------------------------------------//
  2.  
  3. //  Syntax:    plot ( A, KeyTitles, I ) or plot ( X, Y, I )
  4. //        replot ( A, KeyTitles, I ) or replot ( X, Y, I ) or replot ( I )
  5. //        splot ( X, Y, Z, KeyTitles, I )
  6. //        cont ( X, Y, Z, KeyTitles, I )
  7. //        pstring ( "string", I )
  8. //        postplot ( "file_name", "mode", I )
  9. //        latexplot ( "file_name", "mode", I )
  10. //        printplot ( "printer-name", I )
  11. //        psave ( "file_name", A )
  12. //        pssave ( "file_name", X, Y, Z )
  13. //        multiplot ( rows, columns, I )    !!!!!! Special GNUPLOT-contrib needed !!!!!!
  14. //        nomultiplot ( I )        !!!!!! Special GNUPLOT-contrib needed !!!!!!
  15. //        plotyy ( I )            !!!!!! Special GNUPLOT-contrib needed !!!!!!
  16. //        noplotyy ( I )            !!!!!! Special GNUPLOT-contrib needed !!!!!!
  17. //        pclose ( I )
  18. //        setterm ( "term", I )
  19. //        showplot ( I )
  20. //        showpwin ( )
  21. //        phelp ( "string", I)
  22. //        autoscale ( "axis", I )
  23. //        range ( x-start, x-end, y-start, y-end, z-start, z-end, I )
  24. //        xrange ( start, end, I )
  25. //        yrange ( start, end, I )
  26. //        zrange ( start, end, I )
  27. //        xtics ( start, end, incr, I ) or xtics (vector, I ) or xtics ( I )
  28. //        noxtics ( I )
  29. //        ytics ( start, end, incr, I ) or ytics (vector, I ) or ytics ( I )
  30. //        noytics ( I )
  31. //        ztics ( start, end, incr, I ) or ytics (vector, I ) or ytics ( I )
  32. //        noztics ( I )
  33. //        loglog ( I )
  34. //        semilogx ( I )
  35. //        semilogy ( I )
  36. //        nolog ( I )
  37. //        xlabel ( "label_name", I )
  38. //        ylabel ( "label_name", I )
  39. //        zlabel ( "label_name", I )
  40. //        title ( "title_name", I )
  41. //        notitle ( "title_name", I )
  42. //        linestyle ( "line_style", I )
  43. //        pformat ( "format-string", "axis", I )
  44. //        key ( x, y, z, I )    (*)
  45. //        nokey ( I )
  46. //        grid ( I )
  47. //        nogrid ( I )
  48. //        axis ( I )
  49. //        noaxis ( I )
  50. //        label ( "label_text", x, y, z, labelnr, I )    (*)
  51. //        nolabel ( labelnr, I )
  52. //        time ( I )
  53. //        notime ( I )
  54.  
  55. //        (*) Be alert how you send these commands. You will get into trouble
  56. //            if you try to send "I" without fully specified coordinates.
  57. //            Do not leave out "z" or "labelnr" for example.
  58.  
  59. // Description:
  60.  
  61. //  The plot function plots numeric data via the GNUPLOT program. The
  62. //  argument A can be a matrix, or a list of matrices, or a string.
  63. //  plot can also plot a vector Y versus a vector X. X and Y can
  64. //  also be matrixes. 
  65. //  When A is a matrix, columns 2 through N are plotted versus the 1st
  66. //  column. When A is a list of matrices, each matrix is plotted
  67. //  versus it's own 1st column. When A is a string, the string is sent
  68. //  to GNUPLOT as a command.
  69.  
  70. //  plot ( M )                  plots the contents of matrix M
  71. //  plot( X, Y )            plots Y verus X
  72. //  plot ( << M1 ; M2>> )        plots M1, and M2 on the same graph
  73. //  plot ( "set noborder" )        sends the string directly to
  74. //                      GNUPLOT as a command
  75.  
  76. //  Using a list of matrices as an argument to plot is useful when the
  77. //  the independent variable (1st column) of each matrix is different.
  78.  
  79. //  The second and third, and optional argument to plot denotes the plot process
  80. //  number and sends key-titles. The plot() function will open distinct plot
  81. //  processes when given distinct values of N. When this feature is used in a
  82. //  X-windows environment, the effect is to create separate plot windows.
  83. //  The KeyTitles is a string-vector containing the titles to be plotted as keys.
  84. //  They are chosen from the beginning of KeyTitles[1] and so on.
  85. //  For example:
  86.  
  87. //  plot ( M );                plot the contents if matrix M
  88. //  plot ( 2.*M, 1 );            plot 2 times M, to another window
  89. //  plot (<<M1;M2>>, KeyTitles, 2);    plot M1, and M2 on the same graph in another
  90. //                    window with the keytitles from KeyTitles
  91.  
  92. //  The replot() command can be used to replot the last plot. It can also be
  93. //  used to superinpose a new plot in an old plot.
  94.  
  95. //  replot( I );            replot the I-th plot-window
  96. //  replot( A, KeyTitles, I );        superinpose new plot on the I-th plot-window
  97. //  replot( X, Y, I );            superinpose new plot on the I-th plot-window
  98.  
  99. //  For 3D-plotting there are several commands. splot() makes a 3D-surface plot
  100. //  and cont() makes a 2D-contour plot. This is in GNUPLOT a 3D-plot with no 
  101. //  surface.
  102. //  
  103. //  The splot() function splots numeric data via the GNUPLOT program. The
  104. //  argument Z is a matrix as functions of vectors X and Y.
  105.  
  106. //  splot ( X, Y, Z )            splots the contents of matrix Z
  107. //                    versus X and Y
  108. //  splot ( Z )                splots the contents of matrix Z
  109. //                    versus rows and columns
  110. //  splot ( X, Y, [Z1,Z2] )        splots Z1, and Z2 on the same graph
  111. //  cont ( X, Y, Z )            splots the contents of matrix Z
  112. //                    as a 2D-contour-plot
  113. //  cont ( X, Y, [Z1,Z2] )        splots Z1, and Z2 on the same graph
  114. //                    as a 2D-contour-plot
  115.  
  116. //  The psave() and pssave() saves the usual temporary file to a specific, 
  117. //  non-temporary file named "file_name". psave() is for 2D-plots and pssave() 
  118. //  is for 3D-plots. This is useful if you wish to save session-output in a 
  119. //  GNUPLOT-way.
  120.  
  121. //  multiplot() allows you to make multiple plots in one window. After giving 
  122. //  the command you enter multimode. After making rows*columns plot commands 
  123. //  you automaticly leaves this mode. plotyy() allows you to make one plot with 
  124. //  two y-axes. You will enter multimode, and after making two plot commands you 
  125. //  leave. The first plot will be on the left axis and the second on the right. 
  126. //  If you want to leave multiplot() or plotyy() before ending the plot commands
  127. //  just type nomultiplot() or noplotyy().
  128. //  If you want a PostScript output from plots made in multimode you do not 
  129. //  use postplot(). This will not work. plotyy() is for 2D-plots only. 
  130. //  GNUPLOT-3.5 DO NOT SUPPORT THESE FEATURES. If you want to use them 
  131. //  you must add GNUPLOT-contributions and recompile GNUPLOT.
  132.  
  133. //  The pclose function closes (destroys)  the I-th GNUPLOT
  134. //  subprocess. If I = "all", all GNUPLOT subprocess are closed.
  135.  
  136. //  The postplot() function generates a PostScript file named "file_name" 
  137. //  of the current I-th plot. "mode" is further postscript definitions to 
  138. //  GNUPLOT if needed, for example "eps color 'Times-Roman' 14" for making
  139. //  a smaller plot in color with Times-Roman-font size 14.
  140. //  The PostScript plot is saved in a file for printing, or whatever. 
  141. //  Immediately after calling postplot(), the GNUPLOT variables
  142. //  term, and output are reset to there former values.
  143. //  printplot() generates a PostScript file and sends it to the printer.
  144. //  latexplot() generates a LaTeX file named "file_name" of the current 
  145. //  I-th plot. 
  146.  
  147. //  The setterm function allows the user to set/reset the I-th plot's
  148. //  term type. The argument "term" is a string that corresponds to one
  149. //  of GNUPLOT's available term types, for example "vttek".
  150.  
  151. //  The showplot function prints the contents of the I-th plot list to
  152. //  stdout.
  153. //  The showpwin function prints the currently existing plotwindows 
  154. //  to stdout.
  155.  
  156. //  A bunch of often used commands to GNUPLOT has special functions.
  157. //  These could just as well be sent as strings, but this makes life easier.
  158. //  These are range(), xrange(), yrange(), zrange(), xtics(), ytics(), 
  159. //  noxtics(), noytics(), loglog(), semilogx(), semilogy(), nolog(), 
  160. //  autoscale(), xlabel(), ylabel(), zlabel(), 
  161. //  title(), notitle(), linestyle(), pformat(), key(), nokey(), 
  162. //  grid(), nogrid(), axis(), noaxis(), label(), nolabel(), 
  163. //  time() and notime().
  164.  
  165. //  The xtics(), ytics() and ztics() functions sets the tics on the axes. 
  166. //  If it is used as xtics(start,end,incr,I), the tics will be set 
  167. //  for plotwindow I, starting from "start", ending at "end", 
  168. //  with an increment of "incr". 
  169. //  If, however, it is used as xtics([a,b,c,d],I), the tics will 
  170. //  set at "a", "b", "c" and "d" in plotwindow I. 
  171. //  The command xtics(I) will reset the tics in plotwindow I.
  172. //  The noxtics() function results in a tics-less x-axis.
  173.  
  174. //  The plot function is an interface to the GNUPLOT program. The plot
  175. //  function uses temporary files and Rlab's piping capability to
  176. //  transparently plot numerical data via GNUPLOT. Since the plot
  177. //  function is an rfile, it could easily be modified to to use
  178. //  another plotting program.
  179.  
  180. //  To be able to use all commands in this r-file you must add some
  181. //  contributions to GNUPLOT and recompile it. These are "multiplot"
  182. //  and "borders". See the GNUPLOT FAQ for help.
  183.  
  184. //-------------------------------------------------------------------//
  185.  
  186.  
  187.  
  188. _RePlotParameter = zeros(1,100);
  189.  
  190. //
  191. // List to contain plot-object lists.
  192. //
  193.  
  194. static (p);
  195. p = <<>>;
  196.  
  197. //
  198. // Internal plot-related functions
  199. //
  200.  
  201. static (plotl, plotm, splotm, plots);
  202. static (pobj_Create, pobj_Reset, pobj_Destroy);
  203. static (pobj_TmpFileName, pobj_WriteData, pobj_PlotCmd, pobj_RePlotCmd, pobj_SPlotCmd);
  204. static (pobj_PlotKeyTitle, pobj_Plot, pobj_SetRm, pobj_Rm);
  205.  
  206.  
  207.  
  208. //
  209. // User interface to plot functionality
  210. //
  211.  
  212. plot = function ( data, titles, N )
  213. {
  214.     local( WaitAMoment, sizemem, flag1, flag2, flag3 )
  215.     global( _MultiPlotParameter, _MultiOrginParameter, _PlotYyParameter );
  216.  
  217.     flag1 = 0;
  218.     flag2 = 0;
  219.     flag3 = 0;
  220.     // Check the existence titles
  221.     if (exist (titles)) {
  222.     if (class (titles) == "num") {
  223.         if (max (size (titles)) == 1) {
  224.         N = titles;
  225.         else
  226.         flag1=1;
  227.         sizemem = size (data);
  228.         if (data.nr < data.nc) {
  229.             flag2 = 1;
  230.             data = data';
  231.         }
  232.         if (titles.nr < titles.nc) {
  233.             flag3 = 1;
  234.             titles = titles';
  235.         }
  236.         data = [data,titles];
  237.         }
  238.     }
  239.     }
  240.     
  241.     // Set the default plot-object
  242.     if (!exist (N)) { N = 0; }
  243.  
  244.     // Check the existence of p.[N]
  245.     if (max (size (N)) != 1) { error ("plot(): N must be a 1-by-1"); }
  246.     if (exist (p.[N])) {
  247.     pobj_Reset (N);
  248.     else
  249.     pobj_Create (N);
  250.     }
  251.  
  252.     // Check for multiplot and/or plotyy mode
  253.     if (exist (_MultiPlotParameter) || exist (_PlotYyParameter)) {
  254.     // Delay (RLaB is a bit to fast)
  255.     for(i in 1:1000) {
  256.         WaitAMoment=1;
  257.         clear(WaitAMoment);
  258.     }
  259.     // Check for plotyy mode
  260.     if (exist (_PlotYyParameter)) {
  261.         if (_PlotYyParameter==1) {
  262.         printf (" Plot on left y-axis done!\n");
  263.         if (!exist (_MultiPlotParameter)) {
  264.             fprintf (p.[N].prog, "set multiplot\n");
  265.         }
  266.         fprintf (p.[N].prog, "set border 7\n");
  267.         else if (_PlotYyParameter==2) {
  268.             printf (" Plot on right y-axis done!\n");
  269.             fprintf (p.[N].prog, "set border 8\n");
  270.         }   }
  271.         _PlotYyParameter=_PlotYyParameter+1;
  272.     }
  273.     // Check for multiplot mode
  274.     if (exist (_MultiPlotParameter)) {
  275.         printf (" Plot number %i/%i done!\n",_MultiPlotParameter[3],_MultiPlotParameter[1]*_MultiPlotParameter[2]);
  276.         if (_MultiPlotParameter[3]==1) {
  277.         fprintf (p.[N].prog, "set multiplot\n");
  278.         fprintf (p.[N].prog, "set size %s,%s\n",1./_MultiPlotParameter[2],1./_MultiPlotParameter[1]);
  279.         }
  280.         N=_MultiPlotParameter[4];
  281.         fprintf (p.[N].prog, "set orgin %s,%s\n",_MultiOrginParameter[_MultiPlotParameter[3];1],_MultiOrginParameter[_MultiPlotParameter[3];2]);
  282.         if (exist (_PlotYyParameter)) {
  283.         if (_PlotYyParameter==3) {_MultiPlotParameter[3]=_MultiPlotParameter[3]+1; }
  284.         else
  285.         _MultiPlotParameter[3]=_MultiPlotParameter[3]+1;
  286.         }
  287.     }
  288.     }
  289.     
  290.     // Time to plot
  291.     if (class (data) == "num") {
  292.     fprintf (p.[N].prog, "set noparametric\n");    
  293.     pobj_Rm (N);
  294.     plotm (data, N, 1, titles);
  295.     pobj_Plot (N);
  296.     pobj_SetRm (N);
  297.     else if (class (data) == "string") {
  298.         plots (data, N);
  299.         pobj_Plot (N);
  300.         else if (class (data) == "list") {
  301.         pobj_Rm (N);
  302.         plotl (data, N, titles);
  303.         pobj_Plot (N);
  304.         pobj_SetRm (N);    
  305.         else
  306.         error ("Invalid data for plot()");
  307.     }   }   }
  308.     
  309.     // Check for multiplot and/or plotyy mode
  310.     // Check for plotyy mode
  311.     if (exist (_PlotYyParameter)) {
  312.     if (_PlotYyParameter==3) {
  313.         if (!exist (_MultiPlotParameter)) { fprintf (p.[N].prog, "set nomultiplot\n"); }
  314.         fprintf (p.[N].prog, "set border\n");
  315.         clear(_PlotYyParameter);
  316.     }
  317.     }
  318.     // Check for multiplot mode
  319.     if (exist (_MultiPlotParameter)) {
  320.     if (_MultiPlotParameter[3]==_MultiPlotParameter[1]*_MultiPlotParameter[2]+1) {
  321.         fprintf (p.[N].prog, "set nomultiplot\n");
  322.         fprintf (p.[N].prog, "set size %s,%s\n",1,1);
  323.         fprintf (p.[N].prog, "set orgin %s,%s\n",0,0);
  324.         fprintf (p.[N].prog, "set border\n");
  325.         clear(_MultiPlotParameter);
  326.         clear(_MultiOrginParameter);
  327.     }
  328.     }
  329.     
  330.     if (flag1 == 1) { 
  331.     if (flag2 == 0) {
  332.         data = data[;1:sizemem[2]];
  333.         else
  334.         data = data[;1:sizemem[1]];
  335.     }
  336.     if (flag2 == 1) { data = data'; }
  337.     if (flag3 == 1) { titles = titles'; }
  338.     }
  339.  
  340. };
  341.  
  342. //
  343. // User interface to replot functionality
  344. //
  345.  
  346. replot = function ( data, titles, N )
  347. {
  348.     local( sizemem, flag1, flag2, flag3, flag4 );
  349.     global( _MultiPlotParameter, _MultiOrginParameter, _PlotYyParameter );
  350.     global( _RePlotParameter );
  351.     
  352.     flag1 = 0;
  353.     flag2 = 0;
  354.     flag3 = 0;
  355.     flag4 = 0;
  356.     // Check the existence titles
  357.     if (exist (titles)) {
  358.     if (class (titles) == "num") {
  359.         if (max (size (titles)) == 1) {
  360.         N = titles;
  361.         else
  362.         flag1=1;
  363.         sizemem = size (data);
  364.         if (data.nr < data.nc) {
  365.             flag2 = 1;
  366.             data = data';
  367.         }
  368.         if (titles.nr < titles.nc) {
  369.             flag3 = 1;
  370.             titles = titles';
  371.         }
  372.         data = [data,titles];
  373.         }
  374.     }
  375.     }
  376.     
  377.     if (exist (data) && !exist (titles)) {
  378.     if (max(size(data)) == 1) {
  379.         N = data;
  380.         clear(data);
  381.         flag4=1;
  382.     }
  383.     }
  384.     // Set the default plot-object
  385.     if (!exist (N)) { N = 0; }
  386.  
  387.     // Check the existence of p.[N]
  388.     if (max (size (N)) != 1) { error ("plot(): N must be a 1-by-1"); }
  389.     if (exist (p.[N])) {
  390.     pobj_Reset (N);
  391.     else
  392.     pobj_Create (N);
  393.     }
  394.  
  395.     // Time to plot
  396.     if (!exist(data)) {
  397.     fprintf (p.[N].prog, "replot\n");
  398.     if (flag4 == 1) { data = N; }
  399.     return 0;
  400.     }
  401.     if (class (data) == "num") {
  402.     fprintf (p.[N].prog, "set noparametric\n");
  403.     _RePlotParameter[N+1] = _RePlotParameter[N+1]+1;
  404.     pobj_Rm (N);
  405.     replotm (data, N, 1, titles);
  406.     pobj_Plot (N);
  407.     pobj_SetRm (N);
  408.     else if (class (data) == "string") {
  409.         plots (data, N);
  410.         pobj_Plot (N);
  411.         else if (class (data) == "list") {
  412.         pobj_Rm (N);
  413.         plotl (data, N, titles);
  414.         pobj_Plot (N);
  415.         pobj_SetRm (N);    
  416.         else
  417.         error ("Invalid data for replot()");
  418.     }   }   }
  419.  
  420.     if (flag1 == 1) { 
  421.     if (flag2 == 0) {
  422.         data = data[;1:sizemem[2]];
  423.         else
  424.         data = data[;1:sizemem[1]];
  425.     }
  426.     if (flag2 == 1) { data = data'; }
  427.     if (flag3 == 1) { titles = titles'; }
  428.     }
  429.  
  430. };
  431.  
  432.  
  433. //
  434. // User interface to splot functionality
  435. //
  436.  
  437. splot = function ( datax, datay, datazz, titles, N )
  438. {
  439.     local (flag1, flag2, flag3, flag4, flagx, flagy, WaitAMoment)
  440.     global( _MultiPlotParameter, _MultiOrginParameter, _PlotYyParameter );
  441.  
  442.     // Reset flags
  443.     flag1=0;
  444.     flag2=0;
  445.     flag3=0;
  446.     flag4=0;
  447.     flagx=0;
  448.     flagy=0;
  449.  
  450.     // Check what has been sent here
  451.     // One input!
  452.     if (!exist (datay)) {
  453.     datazz=datax;
  454.     datax=1:datazz.nc;
  455.     datax=datax';
  456.     datay=1:datazz.nr;
  457.     datay=datay';
  458.     flag1=flag1+1;
  459.     // Two inputs!
  460.     else if (!exist (datazz)) {
  461.         if (exist (datay)) {
  462.         if (class (datay) == "num") {
  463.             N = datay;
  464.             flag2=flag2+0;
  465.             else
  466.             titles = datay;
  467.             flag2=flag2+1;
  468.         }
  469.         }
  470.         datazz=datax;
  471.         datax=1:datazz.nc;
  472.         datax=datax';
  473.         datay=1:datazz.nr;
  474.         datay=datay';
  475.         flag2=flag2+1;
  476.         // Three inputs!
  477.         else if (!exist (titles)) {
  478.         if (class (datay) != "num") {
  479.             titles = datay;
  480.             N = datazz;
  481.             datazz=datax;
  482.             datax=1:datazz.nc;
  483.             datax=datax';
  484.             datay=1:datazz.nr;
  485.             datay=datay';
  486.             flag3=flag3+1;
  487.         }
  488.         // Four inputs!
  489.         else if (!exist (N)) {
  490.             if (class (titles) == "num") {
  491.             N=titles;
  492.             flag4=flag4+1;
  493.             }
  494.     }   }   }   }
  495.     
  496.     // Transpose x- and y-vectors if nessecary
  497.     if (datax.nc != 1 ) {
  498.     if (datax.nr != 1 ) {
  499.         error ("Invalid data for x-axis (not a vector)");
  500.         else
  501.         datax = datax';
  502.         flagx=flagx+1;
  503.     }
  504.     }
  505.     if (datay.nc != 1 ) {
  506.     if (datay.nr != 1 ) {
  507.         error ("Invalid data for y-axis (not a vector)");
  508.         else
  509.         datay = datay';
  510.         flagy=flagy+1;
  511.     }
  512.     }
  513.     
  514.     // Check how many splots to do
  515.     plotantal=(datazz.nc/datazz.nr)/(datax.nr/datay.nr);
  516.     if (plotantal == int(plotantal)) {
  517.     
  518.     // Set the default splot-object
  519.     if (!exist (N)) { N = 0; }
  520.  
  521.     // Check the existence of p.[N]
  522.     if (max (size (N)) != 1) { error ("splot(): N must be a 1-by-1"); }
  523.     if (exist (p.[N])) {
  524.         pobj_Reset (N);
  525.         else
  526.         pobj_Create (N);
  527.     }
  528.  
  529.     // Check for multiplot and/or plotyy mode
  530.     if (exist (_MultiPlotParameter) || exist (_PlotYyParameter)) {
  531.         // Delay (RLaB is a bit to fast)
  532.         for(i in 1:1000) {
  533.         WaitAMoment=1;
  534.         clear(WaitAMoment);
  535.         }
  536.         // Check for plotyy mode
  537.         if (exist (_PlotYyParameter)) {
  538.         if (_PlotYyParameter==1) {
  539.             if (!exist (_MultiPlotParameter)) {
  540.             fprintf (p.[N].prog, "set multiplot\n");
  541.             }
  542.             fprintf (p.[N].prog, "set border 7\n");
  543.             else if (_PlotYyParameter==2) {
  544.             fprintf (p.[N].prog, "set border 8\n");
  545.         }   }
  546.         _PlotYyParameter=_PlotYyParameter+1;
  547.         }
  548.         // Check for multiplot mode
  549.         if (exist (_MultiPlotParameter)) {
  550.         printf (" Plot number %i/%i done!\n",_MultiPlotParameter[3],_MultiPlotParameter[1]*_MultiPlotParameter[2]);            
  551.         if (_MultiPlotParameter[3]==1) {
  552.             fprintf (p.[N].prog, "set multiplot\n");
  553.             fprintf (p.[N].prog, "set size %s,%s\n",1./_MultiPlotParameter[2],1./_MultiPlotParameter[1]);
  554.         }
  555.         N=_MultiPlotParameter[4];
  556.         fprintf (p.[N].prog, "set orgin %s,%s\n",_MultiOrginParameter[_MultiPlotParameter[3];1],_MultiOrginParameter[_MultiPlotParameter[3];2]);
  557.         if (exist (_PlotYyParameter)) {
  558.             if (_PlotYyParameter==3) {_MultiPlotParameter[3]=_MultiPlotParameter[3]+1; }
  559.             else
  560.             _MultiPlotParameter[3]=_MultiPlotParameter[3]+1;
  561.         }
  562.         }
  563.     }
  564.  
  565.     if (class (datax) != "num") {
  566.         error ("Invalid data class for splot() in x-vector (must be num)");
  567.         else if (class (datay) != "num") {
  568.         error ("Invalid data class for splot() in y-vector (must be num)");
  569.         else if (class (datazz) != "num") {
  570.             error ("Invalid data class for splot() in x-matrix (must be num)");
  571.             else
  572.             fprintf (p.[N].prog, "set parametric\n");
  573.             fprintf (p.[N].prog, "set view 60, 30, 1, 1\n");
  574.             fprintf (p.[N].prog, "set surface\n");
  575.             fprintf (p.[N].prog, "set nocontour\n");
  576.             pobj_Rm (N);
  577.             splotm (datax, datay, datazz, N, 1, titles);
  578.             pobj_Plot (N);
  579.             pobj_SetRm (N);
  580.     }   }   }
  581.     else
  582.     error ("Invalid data for splot(), bad x/y-range in z-matrix");
  583.     }
  584.     
  585.     // Restore the output/input
  586.     if (flag1 == 1) { datax=datazz; }
  587.     if (flag2 == 1) {
  588.     datax=datazz;
  589.     datay=N;
  590.     else if (flag2 == 2) {
  591.         datax=datazz;
  592.         datay=titles;
  593.     }   }
  594.     if (flag3 == 1) {
  595.     datax=datazz;
  596.     datay=titles;
  597.     datazz=N;
  598.     }
  599.     if (flag4 == 1) { titles=N; }
  600.     if (flagx == 1) { datax=datax'; }
  601.     if (flagy == 1) { datay=datay'; }
  602.  
  603.     // Check for multiplot and/or plotyy mode
  604.     // Check for plotyy mode
  605.     if (exist (_PlotYyParameter)) {
  606.     if (_PlotYyParameter==3) {
  607.         if (!exist (_MultiPlotParameter)) { fprintf (p.[N].prog, "set nomultiplot\n"); }
  608.         fprintf (p.[N].prog, "set border\n");
  609.         clear(_PlotYyParameter);
  610.     }
  611.     }
  612.     // Check for multiplot mode
  613.     if (exist (_MultiPlotParameter)) {
  614.     if (_MultiPlotParameter[3]==_MultiPlotParameter[1]*_MultiPlotParameter[2]+1) {
  615.         fprintf (p.[N].prog, "set nomultiplot\n");
  616.         fprintf (p.[N].prog, "set size %s,%s\n",1,1);
  617.         fprintf (p.[N].prog, "set orgin %s,%s\n",0,0);
  618.         fprintf (p.[N].prog, "set border\n");
  619.         clear(_MultiPlotParameter);
  620.         clear(_MultiOrginParameter);
  621.     }
  622.     }
  623. };
  624.  
  625.  
  626.  
  627. //
  628. // User interface to splot functionality as 2D-contour
  629. //
  630.  
  631. cont = function ( datax, datay, datazz, titles, N )
  632. {
  633.     local (flag1, flag2, flag3, flag4, flagx, flagy, WaitAMoment)
  634.     global( _MultiPlotParameter, _MultiOrginParameter, _PlotYyParameter );
  635.  
  636.     // Reset flags
  637.     flag1=0;
  638.     flag2=0;
  639.     flag3=0;
  640.     flag4=0;
  641.     flagx=0;
  642.     flagy=0;
  643.  
  644.     // Check what has been sent here
  645.     // One input!
  646.     if (!exist (datay)) {
  647.     datazz=datax;
  648.     datax=1:datazz.nc;
  649.     datax=datax';
  650.     datay=1:datazz.nr;
  651.     datay=datay';
  652.     flag1=flag1+1;
  653.     // Two inputs!
  654.     else if (!exist (datazz)) {
  655.         if (exist (datay)) {
  656.         if (class (datay) == "num") {
  657.             N = datay;
  658.             flag2=flag2+0;
  659.             else
  660.             titles = datay;
  661.             flag2=flag2+1;
  662.         }
  663.         }
  664.         datazz=datax;
  665.         datax=1:datazz.nc;
  666.         datax=datax';
  667.         datay=1:datazz.nr;
  668.         datay=datay';
  669.         flag2=flag2+1;
  670.         // Three inputs!
  671.         else if (!exist (titles)) {
  672.         if (class (datay) != "num") {
  673.             titles = datay;
  674.             N = datazz;
  675.             datazz=datax;
  676.             datax=1:datazz.nc;
  677.             datax=datax';
  678.             datay=1:datazz.nr;
  679.             datay=datay';
  680.             flag3=flag3+1;
  681.         }
  682.         // Four inputs!
  683.         else if (!exist (N)) {
  684.             if (class (titles) == "num") {
  685.             N=titles;
  686.             flag4=flag4+1;
  687.             }
  688.     }   }   }   }
  689.     
  690.     // Transpose x- and y-vectors if nessecary
  691.     if (datax.nc != 1 ) {
  692.     if (datax.nr != 1 ) {
  693.         error ("Invalid data for x-axis (not a vector)");
  694.         else
  695.         datax = datax';
  696.         flagx=flagx+1;
  697.     }
  698.     }
  699.     if (datay.nc != 1 ) {
  700.     if (datay.nr != 1 ) {
  701.         error ("Invalid data for y-axis (not a vector)");
  702.         else
  703.         datay = datay';
  704.         flagy=flagy+1;
  705.     }
  706.     }
  707.     
  708.     // Check how many splots to do
  709.     plotantal=(datazz.nc/datazz.nr)/(datax.nr/datay.nr);
  710.     if (plotantal == int(plotantal)) {
  711.  
  712.     // Set the default splot-object
  713.     if (!exist (N)) { N = 0; }
  714.  
  715.     // Check the existence of p.[N]
  716.     if (max (size (N)) != 1) { error ("splot(): N must be a 1-by-1"); }
  717.     if (exist (p.[N])) {
  718.         pobj_Reset (N);
  719.         else
  720.         pobj_Create (N);
  721.     }
  722.  
  723.     // Check for multiplot and/or plotyy mode
  724.     if (exist (_MultiPlotParameter) || exist (_PlotYyParameter)) {
  725.         // Delay (RLaB is a bit to fast)
  726.         for(i in 1:1000) {
  727.         WaitAMoment=1;
  728.         clear(WaitAMoment);
  729.         }
  730.         // Check for plotyy mode
  731.         if (exist (_PlotYyParameter)) {
  732.         if (_PlotYyParameter==1) {
  733.             if (!exist (_MultiPlotParameter)) {
  734.             fprintf (p.[N].prog, "set multiplot\n");
  735.             }
  736.             fprintf (p.[N].prog, "set border 7\n");
  737.             else if (_PlotYyParameter==2) {
  738.             fprintf (p.[N].prog, "set border 8\n");
  739.         }   }
  740.         _PlotYyParameter=_PlotYyParameter+1;
  741.         }
  742.         // Check for multiplot mode
  743.         if (exist (_MultiPlotParameter)) {
  744.         if (_MultiPlotParameter[3]==1) {
  745.             fprintf (p.[N].prog, "set multiplot\n");
  746.             fprintf (p.[N].prog, "set size %s,%s\n",1/_MultiPlotParameter[2],1/_MultiPlotParameter[1]);
  747.         }
  748.         N=_MultiPlotParameter[4];
  749.         fprintf (p.[N].prog, "set orgin %s,%s\n",_MultiOrginParameter[_MultiPlotParameter[3];1],_MultiOrginParameter[_MultiPlotParameter[3];2]);
  750.         if (exist (_PlotYyParameter)) {
  751.             if (_PlotYyParameter==3) {_MultiPlotParameter[3]=_MultiPlotParameter[3]+1; }
  752.             else
  753.             _MultiPlotParameter[3]=_MultiPlotParameter[3]+1;
  754.         }
  755.         }
  756.     }
  757.  
  758.     if (class (datax) != "num") {
  759.         error ("Invalid data class for splot() in x-vector (must be num)");
  760.         else if (class (datay) != "num") {
  761.         error ("Invalid data class for splot() in y-vector (must be num)");
  762.         else if (class (datazz) != "num") {
  763.             error ("Invalid data class for splot() in x-matrix (must be num)");
  764.             else
  765.             fprintf (p.[N].prog, "set parametric\n");
  766.             fprintf (p.[N].prog, "set view 0, 0, 1\n");
  767.             fprintf (p.[N].prog, "set nosurface\n");
  768.             fprintf (p.[N].prog, "set contour\n");
  769.             pobj_Rm (N);
  770.             splotm (datax, datay, datazz, N, 1, titles);
  771.             pobj_Plot (N);
  772.             pobj_SetRm (N);
  773.     }   }   }
  774.     else
  775.     error ("Invalid data for splot(), bad x/y-range in z-matrix");
  776.     }
  777.     
  778.     // Restore the output/input
  779.     if (flag1 == 1) { datax=datazz; }
  780.     if (flag2 == 1) {
  781.     datax=datazz;
  782.     datay=N;
  783.     else if (flag2 == 2) {
  784.         datax=datazz;
  785.         datay=titles;
  786.     }   }
  787.     if (flag3 == 1) {
  788.     datax=datazz;
  789.     datay=titles;
  790.     datazz=N;
  791.     }
  792.     if (flag4 == 1) { titles=N; }
  793.     if (flagx == 1) { datax=datax'; }
  794.     if (flagy == 1) { datay=datay'; }
  795.  
  796.     // Check for multiplot and/or plotyy mode
  797.     // Check for plotyy mode
  798.     if (exist (_PlotYyParameter)) {
  799.     if (_PlotYyParameter==3) {
  800.         if (!exist (_MultiPlotParameter)) { fprintf (p.[N].prog, "set nomultiplot\n"); }
  801.         fprintf (p.[N].prog, "set border\n");
  802.         clear(_PlotYyParameter);
  803.     }
  804.     }
  805.     // Check for multiplot mode
  806.     if (exist (_MultiPlotParameter)) {
  807.     if (_MultiPlotParameter[3]==_MultiPlotParameter[1]*_MultiPlotParameter[2]+1) {
  808.         fprintf (p.[N].prog, "set nomultiplot\n");
  809.         fprintf (p.[N].prog, "set size %s,%s\n",1,1);
  810.         fprintf (p.[N].prog, "set orgin %s,%s\n",0,0);
  811.         fprintf (p.[N].prog, "set border\n");
  812.         clear(_MultiPlotParameter);
  813.         clear(_MultiOrginParameter);
  814.     }
  815.     }
  816. };
  817.  
  818.  
  819.  
  820. //
  821. // Send string to GNUPLOT
  822. //
  823.  
  824. pstring = function ( string, N )
  825. {
  826.     if (!exist (N)) { N = 0; }
  827.     if (!exist (p.[N])) { pobj_Create (N); }
  828.     fprintf (p.[N].prog, "%s\n",string);
  829. };
  830.  
  831.  
  832.  
  833. //
  834. // User interface to save a plot ot splot as postscript hardcopy
  835. //
  836.  
  837. postplot = function ( file, mode, N )
  838. {
  839.     local ( flag1 );
  840.     flag1 = 0;
  841.     if (!exist (N) && exist (mode)) {
  842.     if (class (mode) == "num") {
  843.         N = mode;
  844.         flag1 = 1;
  845.     }
  846.     }
  847.  
  848.     if (!exist (N)) { N = 0; }
  849.     if (!exist (p.[N])) { error ("No existing plot to make hardcopy from"); }
  850.  
  851.     // Make hardcopy file
  852.     if (!exist (mode)) { mode="default"; }
  853.     if (class (mode) == "num") { mode="default"; }
  854.     fprintf (p.[N].prog, "set term post %s\n", mode);
  855.     fprintf (p.[N].prog, "set output \"%s\"\n", file);
  856.     fprintf (p.[N].prog, "replot\n");
  857.  
  858.     // Reset to original term type, and replot
  859.     fprintf (p.[N].prog, "set term %s\n", p.[N].term);
  860.     fprintf (p.[N].prog, "replot\n");
  861.  
  862.     if (flag1 == 1) {
  863.     mode = N;
  864.     }
  865. };
  866.  
  867.  
  868.  
  869. //
  870. // User interface to save a plot ot splot as LaTeX hardcopy
  871. //
  872.  
  873. latexplot = function ( file, mode, N )
  874. {
  875.     local ( flag1 );
  876.     flag1 = 0;
  877.     if (!exist (N) && exist (mode)) {
  878.     if (class (mode) == "num") {
  879.         N = mode;
  880.         flag1 = 1;
  881.     }
  882.     }
  883.  
  884.     if (!exist (N)) { N = 0; }
  885.     if (!exist (p.[N])) { error ("No existing plot to make hardcopy from"); }
  886.  
  887.     // Make hardcopy file
  888.     if (!exist (mode)) { mode="default"; }
  889.     if (class (mode) == "num") { mode="default"; }
  890.     fprintf (p.[N].prog, "set term latex %s\n", mode);
  891.     fprintf (p.[N].prog, "set output \"%s\"\n", file);
  892.     fprintf (p.[N].prog, "replot\n");
  893.  
  894.     // Reset to original term type, and replot
  895.     fprintf (p.[N].prog, "set term %s\n", p.[N].term);
  896.     fprintf (p.[N].prog, "replot\n");
  897.  
  898.     if (flag1 == 1) {
  899.     mode = N;
  900.     }
  901. };
  902.  
  903.  
  904. //
  905. // User interface to print a plot ot splot
  906. //
  907.  
  908. printplot = function ( printername, N )
  909. {
  910.     local(fn, flag1);
  911.     
  912.     flag1 = 0;
  913.     if (exist (printername) && !exist(N)) {
  914.     if (class (printername) == "num") {
  915.         N = printername;
  916.         clear(printername);
  917.         flag1 = 1;
  918.     }
  919.     }
  920.     
  921.     if (!exist (N)) { N = 0; }
  922.     if (!exist (p.[N])) { pobj_Create (N); }
  923.     
  924.     // Create tmp-file-name
  925.     fn = "rtmpf";
  926.  
  927.     postplot (fn, "default", N);
  928.         // Delay (RLaB is a bit to fast)
  929.     for(i in 1:1000) {
  930.     WaitAMoment=1;
  931.     clear(WaitAMoment);
  932.     }
  933.     if (exist (printername)) {
  934.     system ("lp -d" + printername + " " + fn);
  935.     else
  936.     system ("lp " + fn);
  937.     }
  938.     // Delay (RLaB is a bit to fast)
  939.     for(i in 1:1000) {
  940.     WaitAMoment=1;
  941.     clear(WaitAMoment);
  942.     }
  943.     system ("rm -f " + fn);
  944.     
  945.     if (flag1 == 1) {
  946.     printername = N;
  947.     }
  948. };
  949.  
  950.  
  951. //
  952. // User interface to save plots as GNUPLOT-datafiles
  953. //
  954.  
  955. psave = function ( file, data )
  956. {
  957.     local (ans, i, nplot, flag1);
  958.  
  959.     flag1 = 0;
  960.     // Check file-name
  961.     if (class (file) != "string") {
  962.     error ("Invalid string for file_name");
  963.     }
  964.  
  965.     // Determine how many lines to save
  966.     nplot = max ([1, data.nc - 1]);
  967.  
  968.     if (nplot > data.nr) {
  969.     printf (" Save %i columns, are you sure [y(es)/n(o)/t(ranspose) (def. no)] ? ", data.nc);
  970.     ans = getline ("stdin");
  971.     if (ans.[1] != "y" && ans.[1] != "t") {
  972.         return 0;
  973.     }
  974.     if (ans.[1] == "t") {
  975.         data = data';
  976.         nplot = max ([1, data.nc - 1]);
  977.         flag1 = 1;
  978.     }
  979.     }
  980.  
  981.     // Generate two column matrices for saving
  982.     for (i in 1:nplot) {
  983.  
  984.     // Write data to file
  985.     if (nplot == 1) {
  986.         pobj_WriteData (real (data), file);
  987.         else
  988.         pobj_WriteData (real (data[;1,i+1]), file);
  989.     }
  990.     }
  991.  
  992.     // Check flag1
  993.     if (flag1 == 1) {
  994.     data = data';
  995.     }
  996. };
  997.  
  998.  
  999.  
  1000. //
  1001. // User interface to save splots as GNUPLOT-datafiles
  1002. //
  1003.  
  1004. pssave = function ( file, datax, datay, datazz)
  1005. {
  1006.     local (ans, i, nsplot, m, n, flag2, flagx, flagy);
  1007.  
  1008.     // Reset flags
  1009.     flag2=0;
  1010.     flagx=0;
  1011.     flagy=0;
  1012.  
  1013.     // Determine how many plots to draw
  1014.     if (!exist (datazz)) { 
  1015.     datazz=datax;
  1016.     datax=1:datazz.nr;
  1017.     datax=datax';
  1018.     datay=1:datazz.nc;
  1019.     datay=datay';
  1020.     flag2=flag2+1;
  1021.     }
  1022.  
  1023.     if (datax.nc != 1 ) {
  1024.     if (datax.nr != 1 ) {
  1025.         error ("Invalid data for x-axis (not a vector)");
  1026.         else
  1027.         datax = datax';
  1028.         flagx=flagx+1;
  1029.     }
  1030.     }
  1031.     if (datay.nc != 1 ) {
  1032.     if (datay.nr != 1 ) {
  1033.         error ("Invalid data for y-axis (not a vector)");
  1034.         else
  1035.         datay = datay';
  1036.         flagy=flagy+1;
  1037.     }
  1038.     }
  1039.  
  1040.     // Create file-name
  1041.     if (!exist (file)) { error ("Invalid string for file_name"); }
  1042.     if (class (file) != "string") { error ("Invalid string for file_name"); }
  1043.  
  1044.     nsplot=(datazz.nr/datazz.nc)/(datax.nr/datay.nr);
  1045.  
  1046.     // Generate three column matrices for splot program
  1047.     // Write data to new data-file
  1048.     for (i in 1:nsplot) {
  1049.     newdata=[];
  1050.     for (m in 1:datax.nr){
  1051.         rownumber=0;
  1052.         for (n in 1:datay.nr){
  1053.         rownumber=rownumber+1;
  1054.         // x-value
  1055.         newdata[rownumber;1]=datax[m];
  1056.         // y-value
  1057.         newdata[rownumber;2]=datay[n];
  1058.         // z-value
  1059.         newdata[rownumber;3]=datazz[m;n+(i-1)*datax.nr];
  1060.         }
  1061.         write (file,real (newdata[;1,2,3]));
  1062.         write (file,"");
  1063.     }
  1064.     close (file);
  1065.     }
  1066.     
  1067.     if (flag2 == 1) {
  1068.     datax=datazz;
  1069.     }
  1070.     if (flagx == 1) { datax=datax'; }
  1071.     if (flagy == 1) { datay=datay'; }
  1072.  
  1073. };
  1074.  
  1075.  
  1076.  
  1077. //
  1078. // Make multiplots
  1079. //
  1080.  
  1081. multiplot = function ( row, col, N )
  1082. {
  1083.     local (i, j, k)
  1084.     global( _MultiPlotParameter, _MultiOrginParameter );
  1085.  
  1086.     if (!exist (N)) { N = 0; }
  1087.     if (!exist (p.[N])) { pobj_Create (N); }
  1088.     _MultiPlotParameter=[row,col,1,N];
  1089.     _MultiOrginParameter=[];
  1090.     printf (" Make %i plots!\n",_MultiPlotParameter[1]*_MultiPlotParameter[2]);    
  1091.     k=1;
  1092.     for (i in 1:row) {
  1093.     for (j in 1:col) {
  1094.         _MultiOrginParameter[k;1]=(j-1)/col;
  1095.         _MultiOrginParameter[k;2]=(row-i)/row;
  1096.         k=k+1;
  1097.     }
  1098.     }
  1099. };
  1100.  
  1101.  
  1102.  
  1103. //
  1104. // Make plot with two y-axes
  1105. //
  1106.  
  1107. plotyy = function ( N )
  1108. {
  1109.     global( _PlotYyParameter );
  1110.  
  1111.     if (!exist (N)) { N = 0; }
  1112.     if (!exist (p.[N])) { pobj_Create (N); }
  1113.     printf (" Make 2 plots!\n The first on left y-axis, the second on the right!\n");
  1114.     _PlotYyParameter=1;
  1115. };
  1116.  
  1117.  
  1118.  
  1119. //
  1120. // User interface to close a GNUPLOT-window
  1121. //
  1122.  
  1123. pclose = function ( N )
  1124. {
  1125.     local (i)
  1126.     if (!exist (N)) { N = 0; }
  1127.     if (N == "all") {
  1128.     for (i in 0:99) {
  1129.         if (exist (p.[i])) {
  1130.         close (p.[i].rmf);
  1131.         close (p.[i].prog);
  1132.         pobj_Destroy (i);
  1133.         }
  1134.     }
  1135.     else
  1136.     if (!exist (p.[N])) { return -1; }
  1137.     close (p.[N].rmf);
  1138.     close (p.[N].prog);
  1139.     pobj_Destroy (N);
  1140.     }
  1141.     return N;
  1142. };
  1143.  
  1144.  
  1145.  
  1146. //
  1147. // Set the terminal type for the I-th GNUPLOT process
  1148. //
  1149.  
  1150. setterm = function ( TERM, N )
  1151. {
  1152.     if (!exist (N)) { N = 0; }
  1153.     if (!exist (p.[N])) { pobj_Create (N); }
  1154.     p.[N].term = TERM;
  1155.  
  1156.     // Now send the "set term" command to GNUPLOT
  1157.     fprintf (p.[N].prog, "set term %s\n", TERM);
  1158. };
  1159.  
  1160.  
  1161.  
  1162. //
  1163. // Print out the plot list
  1164. //
  1165.  
  1166. showplot = function ( N )
  1167. {
  1168.     if (!exist (N)) { N = 0; }
  1169.     if (!exist (p.[N])) {
  1170.     pobj_Create (N);
  1171.     }
  1172.  
  1173.     printf ("\tPlot List %i\n", N);
  1174.     printf ("\t\tTerm:\t\t\t%s\n", p.[N].term);
  1175.     printf ("\t\tOutput:\t\t\t%s\n", p.[N].output);
  1176.     printf ("\t\tTmp Files:\t\t%s\n", p.[N].files);
  1177.     //    printf ("\t\tHardCopy:\t\t%s\n", p.[N].hrd);
  1178.     //    printf ("\t\tHardCopy Files:\t\t%s\n", p.[N].hrdf);
  1179. };
  1180.  
  1181. showpwin = function ()
  1182. {
  1183.     local ( i )
  1184.     for ( i in 0:99) {
  1185.     if (exist (p.[i])) {
  1186.         printf ("\tPlot window number %i exists!\n", i);
  1187.     }
  1188.     }
  1189. };
  1190.  
  1191. //
  1192. // End multiplot mode
  1193. //
  1194.  
  1195. nomultiplot = function(N)
  1196. {
  1197.     global( _MultiPlotParameter, _MultiOrginParameter, _PlotYyParameter );
  1198.  
  1199.     if (!exist (N)) { N = 0; }
  1200.     if (!exist (p.[N])) { pobj_Create (N); }
  1201.     fprintf (p.[N].prog, "set size %s,%s\n",1,1);
  1202.     fprintf (p.[N].prog, "set orgin %s,%s\n",0,0);
  1203.     fprintf (p.[N].prog, "set nomultiplot\n");
  1204.     if (exist (_MultiPlotParameter)) {clear(_MultiPlotParameter);}
  1205.     if (exist (_MultiOrginParameter)) {clear(_MultiOrginParameter);}
  1206.     if (exist (_PlotYyParameter)) {clear(_PlotYyParameter);}
  1207. };
  1208.  
  1209.  
  1210.  
  1211. //
  1212. // End plotyy mode
  1213. //
  1214.  
  1215. noplotyy = function(N)
  1216. {
  1217.     global( _PlotYyParameter );
  1218.  
  1219.     if (!exist (N)) { N = 0; }
  1220.     if (!exist (p.[N])) { pobj_Create (N); }
  1221.  
  1222.     fprintf (p.[N].prog, "set nomultiplot\n");
  1223.     if (exist (_PlotYyParameter)) {clear(_PlotYyParameter);}
  1224. };
  1225.  
  1226.  
  1227.  
  1228. //
  1229. // Here comes a bunch of functions that really is not nessecary.
  1230. // They could be done with string("set key") etc, but this is more convinient.
  1231. //
  1232.  
  1233.  
  1234. xrange = function ( start, end, N )
  1235. {
  1236.     if (!exist (N)) { N = 0; }
  1237.     if (!exist (p.[N])) { pobj_Create (N); }
  1238.     fprintf (p.[N].prog, "set xrange [%s:%s]\n",start,end);
  1239. };
  1240.  
  1241. yrange = function ( start, end, N )
  1242. {
  1243.     if (!exist (N)) { N = 0; }
  1244.     if (!exist (p.[N])) { pobj_Create (N); }
  1245.     fprintf (p.[N].prog, "set yrange [%s:%s]\n",start,end);
  1246. };
  1247.  
  1248. zrange = function ( start, end, N )
  1249. {
  1250.     if (!exist (N)) { N = 0; }
  1251.     if (!exist (p.[N])) { pobj_Create (N); }
  1252.     fprintf (p.[N].prog, "set zrange [%s:%s]\n",start,end);
  1253. };
  1254.  
  1255. range = function ( startx, endx, starty, endy, startz, endz, N )
  1256. {
  1257.     if (exist (startz) && !exist (endz)) { N = startz; }
  1258.     if (exist (starty) && !exist (endy)) { N = starty; }
  1259.     if (!exist (N)) { N = 0; }
  1260.     if (!exist (p.[N])) { pobj_Create (N); }
  1261.     fprintf (p.[N].prog, "set xrange [%s:%s]\n",startx,endx);
  1262.     if (exist(endy)) {
  1263.     fprintf (p.[N].prog, "set yrange [%s:%s]\n",starty,endy);
  1264.     }
  1265.     if (exist(endz)) {
  1266.     fprintf (p.[N].prog, "set zrange [%s:%s]\n",startz,endz);
  1267.     }
  1268. };
  1269.  
  1270. xtics = function ( start, end, incr, N )
  1271. {
  1272.     local ( string, i )
  1273.     if (!exist (start)) { start = 0; }
  1274.     if (!exist (incr)) {
  1275.     if (length(start) > 1) {
  1276.         if (!exist (end)) { end = 0; }
  1277.         if (!exist (p.[end])) { pobj_Create (end); }
  1278.         string = "set xtics (" + num2str(start[1])[1];
  1279.         for (i in 2:length(start)) {
  1280.         string = string + "," + num2str(start[i])[1];
  1281.         }
  1282.         string = string + ")\n";
  1283.         fprintf (p.[end].prog, string);
  1284.         else
  1285.         if (!exist (p.[start])) { pobj_Create (start); }
  1286.         fprintf (p.[start].prog, "set xtics\n");
  1287.     }
  1288.     else
  1289.     if (!exist (N)) { N = 0; }
  1290.     if (!exist (p.[N])) { pobj_Create (N); }
  1291.     fprintf (p.[N].prog, "set xtics %s,%s,%s\n",start,incr,end);
  1292.     }
  1293. };
  1294.  
  1295. noxtics = function ( N )
  1296. {
  1297.     if (!exist (N)) { N = 0; }
  1298.     if (!exist (p.[N])) { pobj_Create (N); }
  1299.     fprintf (p.[N].prog, "set noxtics\n");
  1300. };
  1301.  
  1302. ytics = function ( start, end, incr, N )
  1303. {
  1304.     local ( string, i )
  1305.     if (!exist (start)) { start = 0; }
  1306.     if (!exist (incr)) {
  1307.     if (length(start) > 1) {
  1308.         if (!exist (end)) { end = 0; }
  1309.         if (!exist (p.[end])) { pobj_Create (end); }
  1310.         string = "set ytics (" + num2str(start[1])[1];
  1311.         for (i in 2:length(start)) {
  1312.         string = string + "," + num2str(start[i])[1];
  1313.         }
  1314.         string = string + ")\n";
  1315.         fprintf (p.[end].prog, string);
  1316.         else
  1317.         if (!exist (p.[start])) { pobj_Create (start); }
  1318.         fprintf (p.[start].prog, "set ytics\n");
  1319.     }
  1320.     else
  1321.     if (!exist (N)) { N = 0; }
  1322.     if (!exist (p.[N])) { pobj_Create (N); }
  1323.     fprintf (p.[N].prog, "set ytics %s,%s,%s\n",start,incr,end);
  1324.     }
  1325. };
  1326.  
  1327. noytics = function ( N )
  1328. {
  1329.     if (!exist (N)) { N = 0; }
  1330.     if (!exist (p.[N])) { pobj_Create (N); }
  1331.     fprintf (p.[N].prog, "set noytics\n");
  1332. };
  1333.  
  1334. ztics = function ( start, end, incr, N )
  1335. {
  1336.     local ( string, i )
  1337.     if (!exist (start)) { start = 0; }
  1338.     if (!exist (incr)) {
  1339.     if (length(start) > 1) {
  1340.         if (!exist (end)) { end = 0; }
  1341.         if (!exist (p.[end])) { pobj_Create (end); }
  1342.         string = "set ztics (" + num2str(start[1])[1];
  1343.         for (i in 2:length(start)) {
  1344.         string = string + "," + num2str(start[i])[1];
  1345.         }
  1346.         string = string + ")\n";
  1347.         fprintf (p.[end].prog, string);
  1348.         else
  1349.         if (!exist (p.[start])) { pobj_Create (start); }
  1350.         fprintf (p.[start].prog, "set ztics\n");
  1351.     }
  1352.     else
  1353.     if (!exist (N)) { N = 0; }
  1354.     if (!exist (p.[N])) { pobj_Create (N); }
  1355.     fprintf (p.[N].prog, "set ztics %s,%s,%s\n",start,incr,end);
  1356.     }
  1357. };
  1358.  
  1359. noztics = function ( N )
  1360. {
  1361.     if (!exist (N)) { N = 0; }
  1362.     if (!exist (p.[N])) { pobj_Create (N); }
  1363.     fprintf (p.[N].prog, "set noztics\n");
  1364. };
  1365.  
  1366. loglog = function ( N )
  1367. {
  1368.     if (!exist (N)) { N = 0; }
  1369.     if (!exist (p.[N])) { pobj_Create (N); }
  1370.     fprintf (p.[N].prog, "set nologscale\n");
  1371.     fprintf (p.[N].prog, "set logscale xy\n");
  1372. };
  1373.  
  1374. semilogx = function ( N )
  1375. {
  1376.     if (!exist (N)) { N = 0; }
  1377.     if (!exist (p.[N])) { pobj_Create (N); }
  1378.     fprintf (p.[N].prog, "set logscale x\n");
  1379. };
  1380.  
  1381. semilogy = function ( N )
  1382. {
  1383.     if (!exist (N)) { N = 0; }
  1384.     if (!exist (p.[N])) { pobj_Create (N); }
  1385.     fprintf (p.[N].prog, "set logscale y\n");
  1386. };
  1387.  
  1388. nolog = function ( N )
  1389. {
  1390.     if (!exist (N)) { N = 0; }
  1391.     if (!exist (p.[N])) { pobj_Create (N); }
  1392.     fprintf (p.[N].prog, "set nologscale\n");
  1393. };
  1394.  
  1395. autoscale = function ( axis, N )
  1396. {
  1397.     local( flag )
  1398.     flag = 0;
  1399.     if (!exist (axis) && !exist (N)) {
  1400.     N = 0;
  1401.     axis = "xy";
  1402.     }
  1403.     if (exist (axis) && !exist (N)) {
  1404.     if (class (axis) == "num") {
  1405.         N = axis;
  1406.         axis = "xy";
  1407.         flag = 1;
  1408.     }
  1409.     }
  1410.     if (!exist (p.[N])) { pobj_Create (N); }
  1411.     if (class(axis) != "string") {
  1412.     error ("Must be of class string");
  1413.     }
  1414.     fprintf (p.[N].prog, "set autoscale %s\n",axis);
  1415.     if (flag == 1) { axis = N; }
  1416. };
  1417.  
  1418. xlabel = function ( string, N )
  1419. {
  1420.     if (!exist (N)) { N = 0; }
  1421.     if (!exist (p.[N])) { pobj_Create (N); }
  1422.     fprintf (p.[N].prog, "set xlabel \"%s\"\n",string);
  1423. };
  1424.  
  1425. ylabel = function ( string, N )
  1426. {
  1427.     if (!exist (N)) { N = 0; }
  1428.     if (!exist (p.[N])) { pobj_Create (N); }
  1429.     fprintf (p.[N].prog, "set ylabel \"%s\"\n",string);
  1430. };
  1431.  
  1432. zlabel = function ( string, N )
  1433. {
  1434.     if (!exist (N)) { N = 0; }
  1435.     if (!exist (p.[N])) { pobj_Create (N); }
  1436.     fprintf (p.[N].prog, "set zlabel \"%s\"\n",string);
  1437. };
  1438.  
  1439. title = function ( string, N )
  1440. {
  1441.     if (!exist (N)) { N = 0; }
  1442.     if (!exist (p.[N])) { pobj_Create (N); }
  1443.     fprintf (p.[N].prog, "set title \"%s\"\n",string);
  1444. };
  1445.  
  1446. notitle = function ( N )
  1447. {
  1448.     if (!exist (N)) { N = 0; }
  1449.     if (!exist (p.[N])) { pobj_Create (N); }
  1450.     fprintf (p.[N].prog, "set title\n");
  1451. };
  1452.  
  1453. linestyle = function ( string, N )
  1454. {
  1455.     if (!exist (N)) { N = 0; }
  1456.     if (!exist (p.[N])) { pobj_Create (N); }
  1457.     fprintf (p.[N].prog, "set data style %s\n",string);
  1458. };
  1459.  
  1460. pformat = function ( string1, string2, N )
  1461. {
  1462.     local( flag1);
  1463.     flag1 = 0;
  1464.     if (!exist(string2)) {
  1465.     string2 = "xy";
  1466.     }
  1467.     if (exist (string2) && !exist (N)) {
  1468.     if (class (string2) == "num") {
  1469.         N = string2;
  1470.         string2 = "xy";
  1471.         flag1 = 1;
  1472.     }
  1473.     }
  1474.     if (!exist (N)) { N = 0; }
  1475.     if (!exist (p.[N])) { pobj_Create (N); }
  1476.     fprintf (p.[N].prog, "set format %s \"%s\"\n",string2,string1);
  1477.     if (flag1 == 1) {
  1478.     string1 = string2;
  1479.     string2 = N;
  1480.     }
  1481. };
  1482.  
  1483.  
  1484. key = function ( x, y, z, N )
  1485. {
  1486.     local ( flag1 )
  1487.     flag1 = 0;
  1488.     if (exist(x) && !exist(y)) {
  1489.     N = x;
  1490.     flag1 = 1;
  1491.     }
  1492.     if (!exist (z)) { z = 0; }
  1493.     if (!exist (N)) { N = 0; }
  1494.     if (!exist (p.[N])) { pobj_Create (N); }
  1495.     if (exist(y)) {
  1496.     fprintf (p.[N].prog, "set key %s,%s,%s\n",x,y,z);
  1497.     else
  1498.     fprintf (p.[N].prog, "set key\n");
  1499.     }
  1500.     if (flag1 == 1) {
  1501.     x = N;
  1502.     }
  1503. };
  1504.  
  1505. nokey = function ( N )
  1506. {
  1507.     if (!exist (N)) { N = 0; }
  1508.     if (!exist (p.[N])) { pobj_Create (N); }
  1509.     fprintf (p.[N].prog, "set nokey\n");
  1510. };
  1511.  
  1512. grid = function ( N )
  1513. {
  1514.     if (!exist (N)) { N = 0; }
  1515.     if (!exist (p.[N])) { pobj_Create (N); }
  1516.     fprintf (p.[N].prog, "set grid\n");
  1517. };
  1518.  
  1519. nogrid = function ( N )
  1520. {
  1521.     if (!exist (N)) { N = 0; }
  1522.     if (!exist (p.[N])) { pobj_Create (N); }
  1523.     fprintf (p.[N].prog, "set nogrid\n");
  1524. };
  1525.  
  1526. axis = function ( N )
  1527. {
  1528.     if (!exist (N)) { N = 0; }
  1529.     if (!exist (p.[N])) { pobj_Create (N); }
  1530.     fprintf (p.[N].prog, "set xzeroaxis\n");
  1531.     fprintf (p.[N].prog, "set yzeroaxis\n");
  1532. };
  1533.  
  1534. noaxis = function ( N )
  1535. {
  1536.     if (!exist (N)) { N = 0; }
  1537.     if (!exist (p.[N])) { pobj_Create (N); }
  1538.     fprintf (p.[N].prog, "set noxzeroaxis\n");
  1539.     fprintf (p.[N].prog, "set noyzeroaxis\n");
  1540. };
  1541.  
  1542. label = function ( label, x, y, z, labelnr, N )
  1543. {
  1544.     if (!exist (N)) { N = 0; }
  1545.     if (!exist (p.[N])) { pobj_Create (N); }
  1546.     if (class(label) != "string") {
  1547.     error ("The label must be a string!")
  1548.     }
  1549.     if (exist (labelnr)) {
  1550.     fprintf (p.[N].prog, "set label %s \"%s\" at %s,%s\n", label, labelnr , x, y, z);
  1551.     else
  1552.     fprintf (p.[N].prog, "set label \"%s\" at %s,%s\n", label, x, y, z);
  1553.     }
  1554. };
  1555.  
  1556. nolabel = function ( labelnr, N )
  1557. {
  1558.     if (!exist (N)) { N = 0; }
  1559.     if (!exist (p.[N])) { pobj_Create (N); }
  1560.     if (exist (labelnr)) {
  1561.     fprintf (p.[N].prog, "set nolabel %i\n", labelnr);
  1562.     else
  1563.     fprintf (p.[N].prog, "set nolabel\n");
  1564.     }
  1565. };
  1566.  
  1567. time = function ( N )
  1568. {
  1569.     if (!exist (N)) { N = 0; }
  1570.     if (!exist (p.[N])) { pobj_Create (N); }
  1571.     fprintf (p.[N].prog, "set time\n");
  1572. };
  1573.  
  1574. notime = function ( N )
  1575. {
  1576.     if (!exist (N)) { N = 0; }
  1577.     if (!exist (p.[N])) { pobj_Create (N); }
  1578.     fprintf (p.[N].prog, "set notime\n");
  1579. };
  1580.  
  1581.  
  1582. //====================
  1583. // Static Functions    =
  1584. //====================
  1585.  
  1586. plotl = function ( data, N, titles )
  1587. {
  1588.     local (I, i);
  1589.     I = 1;
  1590.     for (i in members (data)) {
  1591.     if (class (data.[i]) == "num") {
  1592.         // Check for plotting titles
  1593.         pobj_PlotKeyTitle (titles, I, title );
  1594.  
  1595.         plotm (data.[i], N, I, title);
  1596.         I++;
  1597.     }
  1598.     }
  1599. };
  1600.  
  1601.  
  1602.  
  1603. //
  1604. // Set-Up to plot a matrix. Columns 2...N against 1st column.
  1605. //
  1606.  
  1607. plotm = function ( data, N, I, titles )
  1608. {
  1609.     local (ans, fn, i, nplot, title);
  1610.     global( _RePlotParameter );
  1611.     
  1612.     flag1 = 0;
  1613.     // Determine how many lines to draw
  1614.     nplot = max ([1, data.nc - 1]);
  1615.  
  1616.     if (nplot > data.nr) {
  1617.     printf (" Plot %i columns, are you sure [y(es)/n(o)/t(ranspose) (def. no)] ? ", data.nc);
  1618.     ans = getline ("stdin");
  1619.     if (ans.[1] != "y" && ans.[1] != "t") {
  1620.         return 0;
  1621.     }
  1622.     if (ans.[1] == "t") {
  1623.         data = data';
  1624.         nplot = max ([1, data.nc - 1]);
  1625.         flag1 = 1;
  1626.     }
  1627.     }
  1628.  
  1629.     // Generate two column matrices for plot program
  1630.     _RePlotParameter[N+1] = 0;
  1631.     for (i in 1:nplot) {
  1632.     // Create tmp-file-name
  1633.     fn = pobj_TmpFileName (N, i, I);
  1634.  
  1635.     // Check for plotting titles
  1636.     pobj_PlotKeyTitle (titles, i, title );
  1637.  
  1638.     // Write data to tmp-file
  1639.     // Add to plot command
  1640.     if (nplot == 1) {
  1641.         pobj_WriteData (real (data), fn);
  1642.         pobj_PlotCmd (N, fn, title);
  1643.         else
  1644.         pobj_WriteData (real (data[;1,i+1]), fn);
  1645.         pobj_PlotCmd (N, fn, title);
  1646.     }
  1647.     }
  1648.     
  1649.     // Check flag1
  1650.     if (flag1 == 1) {
  1651.     data = data';
  1652.     }
  1653.  
  1654. };
  1655.  
  1656. replotm = function ( data, N, I, titles )
  1657. {
  1658.     local ( ans, fn, i, nplot, title );
  1659.     global( _RePlotParameter );
  1660.     
  1661.     flag1 = 0;
  1662.     // Determine how many lines to draw
  1663.     nplot = max ([1, data.nc - 1]);
  1664.  
  1665.     if (nplot > data.nr) {
  1666.     printf (" Plot %i columns, are you sure [y(es)/n(o)/t(ranspose) (def. no)] ? ", data.nc);
  1667.     ans = getline ("stdin");
  1668.     if (ans.[1] != "y" && ans.[1] != "t") {
  1669.         return 0;
  1670.     }
  1671.     if (ans.[1] == "t") {
  1672.         data = data';
  1673.         nplot = max ([1, data.nc - 1]);
  1674.         flag1 = 1;
  1675.     }
  1676.     }
  1677.  
  1678.     // Generate two column matrices for plot program
  1679.     for (i in 1+_RePlotParameter[N+1]:nplot+_RePlotParameter[N+1]) {
  1680.     // Create tmp-file-name
  1681.     fn = pobj_TmpFileName (N, i, I);
  1682.  
  1683.     // Check for plotting titles
  1684.     pobj_PlotKeyTitle (titles, i, title );
  1685.  
  1686.     // Write data to tmp-file
  1687.     // Add to plot command
  1688.     if (nplot == 1) {
  1689.         pobj_WriteData (real (data), fn);
  1690.         pobj_RePlotCmd (N, fn, title);
  1691.         else
  1692.         pobj_WriteData (real (data[;1,i+1]), fn);
  1693.         pobj_RePlotCmd (N, fn, title);
  1694.     }
  1695.     }
  1696.     
  1697.     // Check flag1
  1698.     if (flag1 == 1) {
  1699.     data = data';
  1700.     }
  1701.  
  1702. };
  1703.  
  1704.  
  1705. //
  1706. // Set-Up to splot a matrix. 
  1707. //
  1708.  
  1709. splotm = function ( datax, datay, datazz, N, I, titles )
  1710. {
  1711.     local ( ans, fn, i, nsplot, m, n, title );
  1712.     global( _RePlotParameter );
  1713.     // Determine how many plots to draw
  1714.     nsplot=(datazz.nc/datazz.nr)/(datax.nr/datay.nr);
  1715.  
  1716.     // Generate three column matrices for splot program
  1717.     _RePlotParameter[N+1] = 0;
  1718.     // Write data to new data-file
  1719.     // Create tmp-file-name
  1720.     for (i in 1:nsplot) {
  1721.     fn = pobj_TmpFileName (N, i, I);
  1722.  
  1723.     // Check for plotting titles
  1724.     pobj_PlotKeyTitle (titles, I, title );
  1725.     newdata=[];
  1726.     for (m in 1:datax.nr){
  1727.         rownumber=0;
  1728.         for (n in 1:datay.nr){
  1729.         rownumber=rownumber+1;
  1730.         // x-value
  1731.         newdata[rownumber;1]=datax[m];
  1732.         // y-value
  1733.         newdata[rownumber;2]=datay[n];
  1734.         // z-value
  1735.         newdata[rownumber;3]=datazz[m;n+(i-1)*datax.nr];
  1736.         }
  1737.         write (fn,real (newdata[;1,2,3]));
  1738.         write (fn,"");
  1739.     }
  1740.     close (fn);
  1741.     // Add to splot command
  1742.     pobj_SPlotCmd (N, fn, title);
  1743.     }
  1744. };
  1745.  
  1746.  
  1747.  
  1748. //
  1749. // Set-Up to splot a matrix. 
  1750. //
  1751.  
  1752.  
  1753.  
  1754.  
  1755. //
  1756. // Form a plain string to send to GNUPLOT as 
  1757. // command
  1758. //
  1759.  
  1760. plots = function ( data, N )
  1761. {
  1762.     // Send the string to GNUPLOT
  1763.  
  1764.     p.[N].pcmd = data + "\n";
  1765. };
  1766.  
  1767.  
  1768.  
  1769. //
  1770. // Create a plot-object.
  1771. //
  1772.  
  1773. pobj_Create = function ( N )
  1774. {
  1775.     local (plist);
  1776.  
  1777.     // The tmp files to plot
  1778.     plist.files = "";
  1779.     // Where the plot command will go
  1780.     plist.pcmd = "";
  1781.  
  1782.     // Init string for plotting program
  1783.     plist.init = "set nogrid\nset data style lines\nset nokey\nset noxzeroaxis\nset noyzeroaxis\n";
  1784.  
  1785.     // The program that draws the plot(s)
  1786. //    sprintf (plist.prog, "|gnuplot #%i", N);
  1787.     sprintf (plist.prog, "|gnupipe <#%i", N);
  1788.  
  1789.     // To remove tmp-files
  1790.  
  1791. //    sprintf (plist.rmf, "|rm -f `cat` #%i", N);
  1792.     sprintf (plist.rmf, "|wipe rtmpf* ~C #%i", N);
  1793.  
  1794.     // Keep track of terminal type, and output
  1795. //    plist.term = "X11";
  1796.      plist.term = "arcsprite";
  1797.      plist.output = "stdout";
  1798.  
  1799.     // Copy the local list into the static plot-object collection
  1800.     p.[N] = plist;
  1801.     fprintf (p.[N].prog, "%s", p.[N].init);
  1802.     fprintf (p.[N].prog, "set term %s\n", p.[N].term);
  1803. };
  1804.  
  1805.  
  1806.  
  1807. //
  1808. // Reset a plot object to plot new data
  1809. //
  1810.  
  1811. pobj_Reset = function ( N )
  1812. {
  1813.  
  1814.     // Close any existing tmp-files that belong
  1815.     // to plot-object N. Reset the file-name list.
  1816.     p.[N].files = "";
  1817.     p.[N].pcmd = "";
  1818. };
  1819.  
  1820.  
  1821.  
  1822. //
  1823. // Destroy a plot-object
  1824. //
  1825.  
  1826. pobj_Destroy = function ( N )
  1827. {
  1828.     if (exist (p.[N])) {
  1829.     clear (p.[N]);    
  1830.     }
  1831. };
  1832.  
  1833.  
  1834.  
  1835. //
  1836. // Create a tmp-file name
  1837. //
  1838.  
  1839. pobj_TmpFileName = function ( N, i, j )
  1840. {
  1841.     local (tmp);
  1842.     sprintf (tmp, "rtmpf%i%i%i", N, i, j);
  1843.     p.[N].files = p.[N].files + " " + tmp;
  1844.     return tmp;
  1845. };
  1846.  
  1847.  
  1848.  
  1849. //
  1850. // Add data-file (tmp-file) to plot object list of stuff
  1851. // to be plotted.
  1852. //
  1853.  
  1854. pobj_WriteData = function ( m, file )
  1855. {
  1856.     write (file, m);
  1857.     close (file);
  1858. };
  1859.  
  1860.  
  1861.  
  1862. //
  1863. // Create the command(s) to plot all the data in the plot object.
  1864. //
  1865.  
  1866. pobj_PlotCmd = function ( N, fn, title )
  1867. {
  1868.     local (tmp);
  1869.  
  1870.     if(p.[N].pcmd == "") {
  1871.     sprintf(tmp, "plot '%s' title '%s'", fn, title);
  1872.     else
  1873.     sprintf(tmp,        ", '%s' title '%s'", fn, title);
  1874.     }
  1875.  
  1876.     p.[N].pcmd = p.[N].pcmd + tmp;
  1877. };
  1878.  
  1879.  
  1880.  
  1881. //
  1882. // Create the command(s) to replot all the data in the plot object.
  1883. //
  1884.  
  1885. pobj_RePlotCmd = function ( N, fn, title )
  1886. {
  1887.     local (tmp);
  1888.  
  1889.     if(p.[N].pcmd == "") {
  1890.     sprintf(tmp, "replot '%s' title '%s'", fn, title);
  1891.     else
  1892.     sprintf(tmp,        ", '%s' title '%s'", fn, title);
  1893.     }
  1894.  
  1895.     p.[N].pcmd = p.[N].pcmd + tmp;
  1896. };
  1897.  
  1898.  
  1899. //
  1900. // Create the command(s) to splot all the data in the splot object.
  1901. //
  1902.  
  1903. pobj_SPlotCmd = function ( N, fn, title )
  1904. {
  1905.     local (tmp);
  1906.  
  1907.     if(p.[N].pcmd == "") {
  1908.     sprintf(tmp, "splot '%s' title '%s'", fn, title);
  1909.     else
  1910.     sprintf(tmp,        ", '%s' title '%s'", fn, title);
  1911.     }
  1912.  
  1913.     p.[N].pcmd = p.[N].pcmd + tmp;
  1914. };
  1915.  
  1916.  
  1917.  
  1918. //
  1919. // Check for plotting titles
  1920. //
  1921.  
  1922. pobj_PlotKeyTitle = function (titles, i, title )
  1923. {
  1924.     if (!exist (titles)) {
  1925.     sprintf (title, "%.4g", i+1);
  1926.     title = "C-" + title;
  1927.     else
  1928.     if (i > length(titles)) {
  1929.         sprintf (title, "%.4g", i+1);
  1930.         title = "C-" + title;
  1931.         else
  1932.         title = titles[i];
  1933.     }
  1934.     }
  1935. };
  1936.  
  1937.  
  1938.  
  1939. //
  1940. // Force the plot program to create the plot
  1941. //
  1942.  
  1943. pobj_Plot = function ( N )
  1944. {
  1945.     //    fprintf ("stdout", "%s\n", p.[N].pcmd);
  1946.     fprintf (p.[N].prog, "%s\n", p.[N].pcmd);
  1947. };
  1948.  
  1949.  
  1950.  
  1951. //
  1952. // Setup so the tmp-files can be removed
  1953. //
  1954.  
  1955. pobj_SetRm = function ( N )
  1956. {
  1957.     fprintf(p.[N].rmf, "%s", p.[N].files);
  1958. };
  1959.  
  1960.  
  1961.  
  1962. //
  1963. // Remove the tmp-files
  1964. //
  1965.  
  1966. pobj_Rm = function ( N )
  1967. {
  1968.     if (length (p.[N].files) != 0) {
  1969.     close (p.[N].rmf);
  1970.     }
  1971. };
  1972.  
  1973.  
  1974.  
  1975. //
  1976. // Provide access to the plot-list
  1977. //
  1978.  
  1979. _pobj_list = function ( N )
  1980. {
  1981.     if (!exist (N)) { N = 0; }
  1982.     return p.[N];
  1983. };
  1984.  
  1985.